<?php


namespace App\Exceptions\JsonResponse;


use App\Exceptions\Code\ErrorCode;
use Illuminate\Support\Arr;

class JsonResponseLastException extends JsonResponseException
{

    public function __construct(string $message = '', ?int $code = ErrorCode::SERVICE_ERROR, \Throwable $previous = null, array $headers = [])
    {
        parent::__construct($message, $code, $previous, $headers);
    }

    /**
     * 详细的异常信息
     * @return array
     */
    protected function getExceptionDetailed()
    {
        $previous = $this->getPrevious();
        return [
            'errcode' => $this->getCode(),
            'errmsg' => $previous->getMessage(),
            'exception' => get_class($previous),
            'file' => $previous->getFile(),
            'line' => $previous->getLine(),
            'trace' => collect($previous->getTrace())->map(function ($trace) {
                return Arr::except($trace, ['args']);
            })->all(),
        ];
    }
}